using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Configuration;
using IDAL;
using Entities;
namespace Bll
{
    public class CategoryBll
    {
        public IList<CategoryInfo> GetAll()
        {
            // Old way, in .Net 1.1
            // string path = ConfigurationSettings.AppSettings["APPDAL"];
            // In .Net 2.0
            string path = ConfigurationManager.AppSettings["APPDAL"];
            string className = path + ".CategoryDAO";
            // Using the evidence given in the config file load the appropriate assembly and class
            Assembly asem = Assembly.Load(path);
            ICategoryDAO dal = (ICategoryDAO)asem.CreateInstance(className);
            return dal.GetAll();
        }

        public bool Insert(CategoryInfo cate)
        {
            string path = ConfigurationManager.AppSettings["APPDAL"];
            string className = path + ".CategoryDAO";
            // Using the evidence given in the config file load the appropriate assembly and class
            Assembly asem = Assembly.Load(path);
            ICategoryDAO dal = (ICategoryDAO)asem.CreateInstance(className);
            return dal.Insert(cate);
        }

        public bool Update(CategoryInfo cate)
        {
            string path = ConfigurationManager.AppSettings["APPDAL"];
            string className = path + ".CategoryDAO";
            // Using the evidence given in the config file load the appropriate assembly and class
            Assembly asem = Assembly.Load(path);
            ICategoryDAO dal = (ICategoryDAO)asem.CreateInstance(className);
            return dal.Update(cate);
        }

        public bool Delete(CategoryInfo cate)
        {
            string path = ConfigurationManager.AppSettings["APPDAL"];
            string className = path + ".CategoryDAO";
            // Using the evidence given in the config file load the appropriate assembly and class
            Assembly asem = Assembly.Load(path);
            ICategoryDAO dal = (ICategoryDAO)asem.CreateInstance(className);
            return dal.Delete(cate);
        }
    }
}
